package leetcode;

public class Main3 {
    public int solution(String s) {
        if (s == null || s.length() == 0) {
            return 0;
        }
        char[] arr = s.toCharArray();
        int ans = 0;
        int count = 1;
        char pre = arr[0];
        for (int i = 1; i < arr.length; i++) {
            char cur = arr[i];
            char next = arr[i + 1];

            if (pre == cur && cur != next && count % 2 == 0) {
                arr[i] = next;
            }

            if (pre != cur && count % 2 == 1) {
                pre = arr[i];
                arr[i] = pre;
                count = 0;
                ans++;
                continue;
            }
            count++;
        }
        return ans;
    }
}
